<template>
	<view>
		
		<view class="head">
			<image :src="info.avatar" mode="" @tap="toPersonal" ></image>
			<view class="title">
				<view class="name">{{ info.nickname }}</view>
				<view class="tags" v-if="info.age!==null||info.heightdata!==null||info.habitation!==null" >{{ info.age!==null&&info.age?info.age+'岁':'' }}<text v-if="info.age!==null&&info.age" >|</text>{{ info.heightdata!==null&&info.heightdata?info.heightdata+'cm':'' }}<text v-if="info.heightdata!==null&&info.heightdata" >|</text>{{ info.habitation!==null&&info.habitation?info.habitation:'' }}</view>
				<view class="tags" v-else ></view>
			</view>
		</view>
		
		<view class="item">
			<view class="item-title">
				{{ info.title }}
			</view>
			<view class="content">
				{{ info.content }}
			</view>
		</view>
		
		<!-- 发起约会状态 -->
		<view v-if="type==1" >
			<view class="reply" v-if="from.fromstatus==1&&mine" >
				<view class="replyIn">
					<image src="../../static/images/heart.png" mode=""></image>
					<text>你已同意他的约会!(点击头像可查看联系方式)</text>
				</view>
			</view>
		</view>
		
		<!-- 约会被拒绝或其他因素 -->
		<view v-if="type==0">
			<view class="reply" v-if="from.fromstatus==3||from.fromstatus==4&&mine" >
				<view class="replyIn">
					<text>你已拒绝他的约会!(点击头像查看更多)</text>
				</view>
			</view>
		</view>
		
		<!-- 底部按钮 -->
		<view class="foot" v-if="type==1&&from.fromstatus!==1" >
			<view class="refuse" @tap="refuse" >拒绝</view>
			<view class="agree" @tap="agree" >同意</view>
		</view>
		
		<!-- <view class="reply" v-if="!foot&&type==1&&show&&from.fromstatus!==0" >
			<text>你已同意他的约会!(点击头像查看更多)</text>
		</view>
		
		<view class="reply" v-if="!foot&&type==0&&show&&from.fromstatus==0" >
			<text>你已拒绝他的约会!(点击头像查看更多)</text>
		</view> -->
		
		<!-- 底部按钮 -->
		<!-- <view class="foot" v-if="foot&&type!==1||from.fromstatus==0" >
			<view class="refuse" @tap="refuse" >拒绝</view>
			<view class="agree" @tap="agree" >同意</view>
		</view> -->
		
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex'
	export default {
		computed: {
			...mapState(['token','userId'])
		},
		data() {
			return {
				id:'',
				fId:'',
				show:false,
				foot:false,
				type:null,
				info:{},
				from:{},
				mine:null
			};
		},
		onLoad(options) {
			console.log(options);
			if(options){
				this.id = options.id;
				this.fId = options.fromId;
				this.type = options.type;
			}
			
			//获取数据
			// this.getData();
			console.log(this.userId);
			
		},
		onShow() {
			
			//获取数据
			this.getData();
			
			console.log(this.type);
			console.log(this.from);
			
		},
		methods:{
			//前往个人详情
			toPersonal() {
				if(this.info.gender==1){
					uni.navigateTo({
						url: '/pages/recommend/personal?type=0&id=' + this.info.fromuserid
					})
				}else{
					uni.navigateTo({
						url: '/pages/recommend/personal?type=1&id=' + this.info.fromuserid
					})
				}
			},
			async getData() {
				try {
					let params = {
						token: this.token,
						msgId:this.id,
						formId:this.fId
					};
					let res = await this.$request.request.get('/api/user/msgDetail', params)
					console.log(res);
					if (res.code == 200) {
						this.info = res.data.detail;
						this.from = res.data.from;
						if(this.info.msg == '太棒了！他（她）同意了您的约会邀请！'||this.info.msg == '他（她）拒绝了您的约会邀请'){
							this.mine = false;
						}else{
							this.mine = true;
						}
						console.log(this.mine)
					}
				} catch (err) {
					this.$request.error(err, this)
				}
			},
			//点击了拒绝
			refuse(){
				this.doRefuse();
			},
			//点击了同意
			agree(){
				this.doPay();
			},
			//拒绝接口
			async doRefuse() {
				try {
					let params = {
						token: this.token,
						fromMsgId: this.info.id,
						toUserId :this.info.fromuserid,
						status: 1
					};
					let res = await this.$request.request.post('/api/user/appointmentStatus', params)
					console.log(res);
					if (res.code == 200) {
						uni.showToast({
							title:res.msg
						});
						setTimeout(()=> {
							uni.navigateBack();
						},800)
					}
				} catch (err) {
					this.$request.error(err, this)
				}
			},
			//同意调用支付
			async doPay() {
				try {
					let params = {
						token: this.token,
						fromMsgId: this.info.id,
						toUserId :this.info.fromuserid,
						status: 0
					};
					let res = await this.$request.request.post('/api/user/appointmentStatus', params)
					console.log(res);
					if (res.code == 200) {
						//跳转支付页
						uni.navigateTo({
							url: '/pages/my/payInfo?orderNo=' + res.data.orderNo + '&type=3' + '&price=' + res.data.price + '&title=' +
								res.data.title
						})
					}
				} catch (err) {
					this.$request.error(err, this)
				}
			},
		}
	}
</script>

<style lang="scss">
@import 'message_detail.scss'
</style>
